package com.example.SpringBootRestful;



        import org.springframework.context.annotation.Configuration;

        import springfox.documentation.builders.ApiInfoBuilder;
        import springfox.documentation.builders.PathSelectors;
        import springfox.documentation.builders.RequestHandlerSelectors;
        import springfox.documentation.service.ApiInfo;
        import springfox.documentation.spi.DocumentationType;
        import springfox.documentation.spring.web.plugins.Docket;
        import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的配置类
 *
 * @author Daniel
 *
 */

@Configuration   //让Spring来加载该类配置
@EnableSwagger2   //开启Swagger2
public class Swagger2 {

    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //指定包路径,此路径下的接口会在Swagger2中显示,如果要忽略的话加上注解(@ApiIgnore)
                .apis(RequestHandlerSelectors.basePackage("com.sh.daniel.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    //api展示的相关信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("在spring-boot中使用Swagger2构建restful api")
                //描述
                .description("关于用户操作的相关接口信息")
                //版本号
                .version("1.0")
                .build();
    }

}